package com.csii.pos.activiti;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.adhoc.annotation.OperationLog;
import com.csii.pos.activiti.service.ActivitiUofPlanService;
import com.csii.pos.uofplan.UofPlanPo;
import com.csii.result.APIResult;
import com.csii.result.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: ActivitiUofPlanController
 * @Author: zhanghao
 * @description: 资金计划的审批流控制层
 * @Date: 2021/7/20 23:04
 * @Version: 1.0
 */
@RestController
@RequestMapping("/actUof")
public class ActivitiUofPlanController {

    @Autowired
    private ActivitiUofPlanService activitiUofPlanService;

    /**
     * 部署流程
     */
    @RequestMapping("/deploy")
    public APIResult<?> deploy() {
        activitiUofPlanService.deploy();
        return APIResult.successResult("部署成功!");
    }

    /**
     * 新增的资金计划进行确认操作,可以批量确认操作,即启动和提交审批.
     * @param uofPlanPo 需要提交审批的数据的主键
     * @return
     */
    @OperationLog(value = "资金计划提交审批")
    @RequestMapping("/startAndSubmit")
    public APIResult<?> startAndSubmit(@RequestBody UofPlanPo uofPlanPo){
        activitiUofPlanService.startAndSubmit(uofPlanPo.getUofItemSn());
        return APIResult.successResult("确认提交审批成功!");
    }

    /**
     * 提交资金计划申请
     */
    /*@RequestMapping("/submit")
    public APIResult<?> submit(@RequestBody List<String> idList){
        activitiUofPlanService.submit(idList);
        return APIResult.successResult("提交审批申请成功!");
    }*/

    //删除提交审批申请
    /*@RequestMapping("/delete")
    public APIResult<?> delete(@RequestBody UofPlanPo uofPlanPo){
        activitiUofPlanService.delete(uofPlanPo.getUofItemSn().toString());
        return APIResult.successResult("删除审批申请成功!");
    }*/


    /**
     * 查询需要审批的数据
     * @return
     */
    @OperationLog(value = "资金计划审批流程数据查询")
    @RequestMapping("/findApproveAllInfo")
    public APIResult<?> findApproveAllInfo(@RequestBody UofPlanPo uofPlanPo){
//        无分页
//        Page<UofPlanPo> page = new Page<>(uofPlanPo.getPageNo(), uofPlanPo.getPageSize());
//        return APIResult.successResult(activitiUofPlanService.findAllInfo(uofPlanPo));
        Page<UofPlanPo> page = new Page<>(uofPlanPo.getPageNo(), uofPlanPo.getPageSize());
        IPage<UofPlanPo> uofPlanPoIPage = activitiUofPlanService.findAllInfo(page, uofPlanPo);
        return APIResult.successResult(PageVo.getPageVoFromIPage(uofPlanPoIPage));
    }


    /**
     * 审批人员同意
     * @param uofPlanPo 操作的业务实体对象,必传主键.
     */
    @OperationLog(value = "资金计划审批同意操作")
    @RequestMapping("/agree")
    public APIResult<?> agree(@RequestBody UofPlanPo uofPlanPo){
        activitiUofPlanService.agreeByApprover(uofPlanPo);
        return APIResult.successResult("同意操作成功!");
    }


    //
    /**
     * 审批人拒绝
     * @param uofPlanPo 操作的业务实体对象,必传主键.
     */
    @OperationLog(value = "资金计划审批拒绝操作")
    @RequestMapping("/reject")
    public APIResult<?> reject(@RequestBody UofPlanPo uofPlanPo){
        activitiUofPlanService.rejectByApprover(uofPlanPo);
        return APIResult.successResult("拒绝操作成功!");
    }

    /**
     * 审批人驳回
     * @param uofPlanPo 操作的业务实体对象,必传主键.
     */
    @OperationLog(value = "资金计划审批驳回操作")
    @RequestMapping("/refute")
    public APIResult<?> refute(@RequestBody UofPlanPo uofPlanPo){
        activitiUofPlanService.refuteByApprover(uofPlanPo);
        return APIResult.successResult("驳回操作成功!");
    }

}
